<?php
/**
 * 将没有缩略图的加入到队列中
 */
include_once '../lib/config.php';
include_once '../lib/Db.class.php';
include_once '../lib/Model.class.php';
include_once '../lib/Upyun.class.php';
include_once '../lib/function.php';

$redis = new Redis();
$redis->connect(REDIS_IP, "6379"); //php客户端设置的ip及端口
if (!$redis) {
    die('redis connect fail');
}

$redis->auth(REDIS_PASS);
$redis->select(5);

$GLOBALS['config']['master']['db_database'] = 'dc211';
$GLOBALS['config']['slave']['db_database'] = 'dc211';

$model = new Db;
$startid = 0;

$longopts = array(
    'startid::',
);

$options = getopt('', $longopts);
if (isset($options['startid'])) {
    $startid = (int) $options['startid'];
} else {
    $startid = (int) $redis->get('dc211:last_startid');
}

while (true) {
    $list = $model->query("select id,slink,hasThumb from slist where id>{$startid} and hasThumb=0 order by id asc limit 50");
    if (!$list) {
        var_dump('finished!');
        break;
    }

    foreach ($list as $item) {
        $redis->rPush("dc211:slist", json_encode($item));

        $startid = $item['id'];
    }

    echo ("Next: {$startid} \n");
    $redis->set('dc211:last_startid', $startid);
}

sleep(5);
